package com.example.app.ui.notifications;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;


import com.example.app.R;
import com.example.app.databinding.FragmentNotificationsBinding;
import com.example.app.Entity.User;

import java.util.ArrayList;
import java.util.List;
public class NotificationsFragment extends Fragment {
    private FragmentNotificationsBinding binding;
    List<User> userList=new ArrayList<>();
    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentNotificationsBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        AppCompatActivity activity = (AppCompatActivity) getActivity();
        ActionBar supportActionBar = activity.getSupportActionBar();
        if (supportActionBar != null) {
            View customView = supportActionBar.getCustomView();
            TextView textViewTitle = customView.findViewById(R.id.textView_title);
            ImageView imageViewLogo = customView.findViewById(R.id.imageView_logo);
            ImageView imageViewLogo2 = customView.findViewById(R.id.imageView_logo2);
            textViewTitle.setText("发现");
            imageViewLogo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    System.out.println("--------------------------------------------------------------------------------------");
                }
            });

        }
        ListView listView = root.findViewById(R.id.notificationelv);
        List<User> userList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
//            userList.add(new User("发现 " + i, String.valueOf(i)));
        }
        SharedPreferences sharedPreferences = requireContext().getSharedPreferences("user_credentials", Context.MODE_PRIVATE);
        String username = sharedPreferences.getString("username", null);
        String password = sharedPreferences.getString("password", null);
        System.out.println("Notification   \n  "+username+"   \n"+password);
        NotificationAdapter adapter = new NotificationAdapter(requireContext(), userList);
        listView.setAdapter(adapter);

        return root;
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}